package com.css.fxfzxczh.modules.lossAssessment.houseCategoryArea.controller;

import com.css.fxfzxczh.base.response.RestResponse;
import com.css.fxfzxczh.modules.lossAssessment.houseCategoryArea.entity.HouseCategoryArea;
import com.css.fxfzxczh.modules.lossAssessment.houseCategoryArea.param.QueryParam;
import com.css.fxfzxczh.modules.lossAssessment.houseCategoryArea.service.HouseCategoryAreaService;
import com.css.fxfzxczh.modules.lossAssessment.houseCategoryArea.vo.BuildGridFindAllVo;
import com.css.fxfzxczh.util.PlatformObjectUtils;
import com.css.fxfzxczh.util.ResponseCreator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author Dbj
 * @date 2023年05月31日  17:52
 */
@RestController
@RequestMapping("/hca")
@Validated
public class HouseCategoryAreaController {
    @Resource
    HouseCategoryAreaService houseCategoryAreaService;

    /**
     * 大区划上传13表数据时先删除保存在现场调查中保存的之前的数据
     */
    @PostMapping("/deleteAndSavePcData")
    public RestResponse deleteAndSavePcData(@RequestBody Map<String,Object> map){
         houseCategoryAreaService.deleteAndSavePcData(map);
         return ResponseCreator.createSuccessResponse("操作成功");
    }

    /**
     * 获取大区划上传13表数据
     */
    @GetMapping("/getAndSavePcData")
    public RestResponse getAndSavePcData(){
        houseCategoryAreaService.getAndSavePcData();
        return ResponseCreator.createSuccessResponse("操作成功");
    }

    /**
     * 获取某个地震事件下不同评估子区下各个区县下不同房屋用途下的各个结构类型的面积
     */
    @GetMapping("/getHouseCategoryArea")
    public RestResponse getHouseCategoryArea(QueryParam queryParam){
        List<HouseCategoryArea> list = houseCategoryAreaService.getHouseCategoryArea(queryParam);
        return ResponseCreator.createSuccessResponse(list);
    }

    /**
     * 点击总建筑面积生成新一轮的面积数据
     */
    @GetMapping("/mathHouseCategoryArea")
    public RestResponse mathHouseCategoryArea(@RequestParam(value = "dataFrom") String dataFrom,
                                              @RequestParam(value = "attachId",required = false)String attachId,
                                              @RequestParam(value = "ratio",required = false)String ratio,
                                              @RequestParam(value = "versionCode",required = false)String versionCode) throws Exception {
        List<HouseCategoryArea> list = houseCategoryAreaService.mathHouseCategoryArea(dataFrom,attachId,ratio,versionCode);
        return ResponseCreator.createSuccessResponse(list);
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete")
    public RestResponse delete(@RequestBody Map<String,String> map){
        if(PlatformObjectUtils.isEmpty(map.get("xshcaId"))){
            return ResponseCreator.createFailResponse("请选择要删除的数据");
        }
        return houseCategoryAreaService.delete(map.get("xshcaId"));
    }


    /**
     * 修改页面数据回显查询
     */
    @GetMapping("/updatePage")
    public RestResponse updatePage(String xshcaId){
        if(PlatformObjectUtils.isEmpty(xshcaId)){
            return ResponseCreator.createFailResponse("请选择要修改的数据");
        }
        return houseCategoryAreaService.updatePage(xshcaId);
    }

    /**
     * 修改数据
     */
    @PostMapping("/toUpdate")
    public RestResponse toUpdate(@Valid @RequestBody HouseCategoryArea area){
        return houseCategoryAreaService.toUpdate(area);
    }


    /**
     * 获取该地震事件下的所关联的省信息
     */
    @GetMapping("/getProvinceList")
    public RestResponse getProvinceList(String xsemCode) throws  Exception{
        return houseCategoryAreaService.getProvinceList(xsemCode);
    }

    /**
     * 获取市或区县的信息
     */
    @GetMapping("/getAreaList")
    public RestResponse getAreaList(String code,String level){
        return houseCategoryAreaService.getAreaList(code,level);
    }

    /**
     * 房屋用途
     */
    @GetMapping("/getHouseUseTo")
    public RestResponse getHouseUseTo(){
        return ResponseCreator.createSuccessResponse(houseCategoryAreaService.getHouseUseTo());
    }
}
